// 用户管理模块接口
import request from '@/utils/request'
import type { UserResponseData, User, AllRoleResponseData, SetRoleData } from './type'
enum API {
    // 获取全部已有用户账号信息
    ALLUSER_URL = '/admin/acl/user/',
    // 添加新的账号
    ADDUSER_URL = '/admin/acl/user/save',
    // 修改已有的用户账号
    UPDATEUSER_URL = '/admin/acl/user/update',
    // 获取全部职位和当前账号拥有的职位接口
    ALLROLE_URL = '/admin/acl/user/toAssign/',
    // 给已有的用户分配职位接口
    SETROLE_URL = '/admin/acl/user/doAssignRole',
    // 单个用户删除
    DELETEUSER_URL = '/admin/acl/user/remove/',
    // 批量删除
    DELETEALLUSER_URL = '/admin/acl/user/batchRemove'
}

// 获取全部已有用户账号信息
export const userInfoAPI = (page: number, limit: number, username: string) => request.get<any, UserResponseData>(API.ALLUSER_URL + `${page}/${limit}/?username=${username}`)

// 添加与修改
export const addOrUpdateUserAPI = (data: User) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data)
    }
}

// 获取全部职位和当前账号拥有的职位接口
export const allRoleAPI = (userId: number) => request.get<any, AllRoleResponseData>(API.ALLROLE_URL + userId)

// 给已有的用户分配角色接口
export const setUserRoleAPI = (data: SetRoleData) => request.post(API.SETROLE_URL, data)

// 单个用户删除
export const removeUserAPI = (userId: number) => request.delete<any, any>(API.DELETEUSER_URL + userId)

// 批量删除
export const selectRemoveUserAPI = (idList: number[]) => request.delete<any, any>(API.DELETEALLUSER_URL, {data: idList})